<!-- 报警消息接收人管理 -->
<template>
	<el-card shadow="hover">
		<el-tabs v-model="activeName" type="card">
			<el-tab-pane label="为管理用户关联小区" name="first">
				<first v-if="activeName.valueOf() == 'first'" :curTab="activeName" :deptData="data.deptData" :deptMap="data.deptMap" />
			</el-tab-pane>
			<el-tab-pane label="通过小区查关联管理用户" name="second">
				<second v-if="activeName.valueOf() == 'second'" :curTab="activeName" :deptData="data.deptData" :deptMap="data.deptMap" />
			</el-tab-pane>
		</el-tabs>
	</el-card>
</template>

<script lang="ts" setup name="alarm-msg">
import { reactive, onMounted, ref } from 'vue';
import { getDeptTree } from '/@/api/system/user';

import first from './first.vue';
import second from './second.vue';
const activeName = ref('first');

const data = reactive({
	deptData: [],
	deptMap: <any>{},
});

onMounted(() => {
	getDeptTreeData();
});

//
function getDeptTreeData() {
	getDeptTree().then((res: any) => {
		res.data.deps[0].children = res.data.deps[0].children.filter((item: any) => {
			return !['安装人员', '其它', '测试'].includes(item.deptName);
		});

		data.deptData = res.data.deps;
		getTreeMap(res.data.deps);
	});
}

function getTreeMap(treeList: Array<any>) {
	treeList.forEach((item: any) => {
		data.deptMap[item.deptId] = item.deptName;
		if (item.children) {
			getTreeMap(item.children);
		}
	});
}
</script>
